﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraPrintingLinks;
using DevExpress.XtraPrinting;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;

namespace NNLInterface
{
    public partial class common 
    {

        /// <summary>
        /// 初始化数据表格
        /// </summary>
        /// <param name="ListView">表格中的ListView对象</param>
        /// <param name="style">表格显示模式</param>
        public static void subIniGrid(DevExpress.XtraGrid.Views.Grid.GridView ListView, enumGridStyle style)
        {

            //设定小数位数
            for (int i = 0; i < ListView.Columns.Count; i++)
            {
                //if (ListView.Columns[i].ColumnType.ToString() == "System.Decimal")
                //{
                //    //ListView.Columns[i].SummaryItem.DisplayFormat = "{0:c}";
                //    ListView.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                //    ListView.Columns[i].DisplayFormat.FormatString = "n4";
                //    ListView.Columns[i].AppearanceHeader.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                //    ListView.Columns[i].AppearanceHeader.Options.UseTextOptions = true;
                    //设置自动筛选行默认条件为包含（%条件%）
                    ListView.Columns[i].OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains;
                    //如果是超级用户，则不能过滤数据表格
                    //if (common._userid != "admin")
                    //{
                    //    ListView.Columns[i].OptionsFilter.AllowFilter = false;
                    //    ListView.OptionsFilter.AllowColumnMRUFilterList=false;
                    //    ListView.OptionsFilter.AllowFilterEditor=false;
                    //    ListView.OptionsFilter.AllowMRUFilterList=false;
                    //}
                //}
            }
            
            //common.sysParameter.CurRowBcolor = Color.WhiteSmoke;
         

            ListView.IndicatorWidth = 50;

            switch (style)
            {
                case enumGridStyle.ViewStyle:
                    ListView.OptionsView.ColumnAutoWidth  = false;
                    ListView.OptionsView.EnableAppearanceEvenRow = false;
                    ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.CellFocus ;
                    ListView.Appearance.Row.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
                    ListView.Appearance.FocusedRow.BackColor = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.FocusedRow.BackColor2 = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.FocusedRow.ForeColor = Color.Black;

                    ListView.Appearance.SelectedRow.BackColor = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.SelectedRow.BackColor2 = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.SelectedRow.ForeColor = Color.Black;

                    ListView.Appearance.HideSelectionRow.BackColor = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.HideSelectionRow.BackColor2 = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.Black;
                    //ListView.HorzScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
                    //ListView.VertScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
                    //ListView.Appearance.OddRow.BackColor = System.Drawing.Color.White;
                    //ListView.Appearance.OddRow.BackColor2 = System.Drawing.Color.White;

                    //ListView.Appearance.EvenRow.BackColor = System.Drawing.Color.WhiteSmoke;
                    //ListView.Appearance.EvenRow.BackColor2 = System.Drawing.Color.WhiteSmoke;


                    //ListView.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.Beige;
                    //ListView.Appearance.HideSelectionRow.BackColor2 = System.Drawing.Color.Beige;
                    //ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.Black;
                    for (int col = 0; col < ListView.Columns.Count; col++)
                    {
                        ListView.Columns[col].OptionsColumn.AllowEdit = true;
                        ListView.Columns[col].OptionsColumn.AllowFocus = true;
                        ListView.Columns[col].OptionsColumn.ReadOnly = true;

                    }
                    

                    break;
                case enumGridStyle.InputStyle:
                    //ListView.OptionsBehavior.Editable = true;
                
                    // 默认当单击单元格或进入单元格时，选中单元格内容
                    ListView.OptionsBehavior.AutoSelectAllInEditor = true;
                    // 自动建立列
                    ListView.OptionsBehavior.AutoPopulateColumns = true;

                    //View Options选项
                    //默认显示过滤面板，即当Header能定制过滤，是否显示过滤面板
                    ListView.OptionsFilter.ShowAllTableValuesInFilterPopup = true;
                    // 默认不显示分组面板
                    ListView.OptionsView.ShowGroupPanel = false;
                    // 默认显示指示器
                    ListView.OptionsView.ShowIndicator = true;
                    // 默认显示列的总宽度和视图的宽度不相等
                    ListView.OptionsView.ColumnAutoWidth = false;
                    // 默认显示视图脚
                    //ListView.OptionsView.ShowFooter =true ;

                    // Print Options选项
                    // 不能自动宽度
                    ListView.OptionsPrint.AutoWidth = false;

                    // Cell Navigation Options选项
                    // 按Enter进入下一列
                    ListView.OptionsNavigation.EnterMoveNextColumn = true;

                    for (int col = 0; col < ListView.Columns.Count; col++)
                    {
                        ListView.Columns[col].OptionsColumn.AllowEdit = true;
                        ListView.Columns[col].OptionsColumn.AllowFocus = true;

                    }

                    // 焦点自动到新行
                    ListView.OptionsNavigation.AutoFocusNewRow = true;
                    ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.CellFocus;

                    //ListView.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
                    
                    ListView.Appearance.Row.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;

                    //ListView.Appearance.FocusedRow.BackColor = System.Drawing.Color.White;
                    //ListView.Appearance.FocusedRow.BackColor2 = System.Drawing.Color.White;
                    //ListView.Appearance.FocusedRow.ForeColor = Color.Black;

                    //ListView.Appearance.SelectedRow.BackColor = System.Drawing.Color.White;
                    //ListView.Appearance.SelectedRow.BackColor2 = System.Drawing.Color.White;
                    //ListView.Appearance.SelectedRow.ForeColor = Color.Black;

                    //ListView.Appearance.FocusedCell.BackColor = System.Drawing.Color.White;
                    //ListView.Appearance.FocusedCell.ForeColor = System.Drawing.Color.Black;

                    break;
                default:
                    //StyleFormatCondition styleCondition = new StyleFormatCondition();
                    //ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None;
                    //ListView.OptionsSelection.EnableAppearanceFocusedRow = false;
                    //ListView.OptionsSelection.EnableAppearanceFocusedCell = false;
                    //ListView
                    //// Adds the style condition to the collection
                    //ListView.FormatConditions.Add(styleCondition);
                    //styleCondition.Value1 = 0;
                    //styleCondition.Value2 = 0;
                    //// Modifying the appearance settings
                    //styleCondition.Appearance.BackColor = Color.White;
                    //styleCondition.Appearance.Font = new Font(ListView.Appearance.Row.Font, FontStyle.Bold);
                    //styleCondition.Appearance.ForeColor = Color.White;
                    //styleCondition.Condition = FormatConditionEnum.Equal;
                    //styleCondition.ApplyToRow = false;

                    ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
                    ListView.Appearance.Row.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
                    ListView.Appearance.FocusedRow.BackColor = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.FocusedRow.BackColor2 = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.FocusedRow.ForeColor = Color.Black;

                    ListView.Appearance.SelectedRow.BackColor = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.SelectedRow.BackColor2 = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.SelectedRow.ForeColor = Color.Black;

                    ListView.Appearance.HideSelectionRow.BackColor = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.HideSelectionRow.BackColor2 = common.sysParameter.CurRowBcolor;
                    ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.Black;

                    ListView.OptionsView.ColumnAutoWidth = false;
                    ListView.OptionsView.EnableAppearanceEvenRow = false;
                    ListView.IndicatorWidth = 40;
                    ListView.HorzScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Auto;
                    ListView.VertScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Auto;
                    for (int col = 0; col < ListView.Columns.Count; col++)
                    {
                        ListView.Columns[col].OptionsColumn.AllowEdit = false;
                        ListView.Columns[col].OptionsColumn.AllowFocus = true;

                    }
                    //ListView.Appearance.OddRow.BackColor = System.Drawing.Color.White;
                    //ListView.Appearance.OddRow.BackColor2 = System.Drawing.Color.White;

                    //ListView.Appearance.EvenRow.BackColor = System.Drawing.Color.WhiteSmoke;
                    //ListView.Appearance.EvenRow.BackColor2 = System.Drawing.Color.WhiteSmoke;

                    //ListView.Appearance.FocusedRow.BackColor = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.FocusedRow.BackColor2 = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.FocusedRow.ForeColor = Color.White;

                    //ListView.Appearance.SelectedRow.BackColor = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.SelectedRow.BackColor2 = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.SelectedRow.ForeColor = Color.White;

                    //ListView.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.HideSelectionRow.BackColor2 = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.White;

                    //ListView.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.HideSelectionRow.BackColor2 = System.Drawing.Color.RoyalBlue;
                    //ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.White;

                    ListView.Appearance.HeaderPanel.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                    ListView.Appearance.HeaderPanel.Options.UseTextOptions = true;
                    ListView.OptionsView.RowAutoHeight = false;
                    ListView.ColumnPanelRowHeight = 30;
                    ////设定小数位数
                    //for (int i = 0; i < ListView.Columns.Count; i++)
                    //{
                    //    if (ListView.Columns[i].ColumnType.ToString() == "System.Decimal")
                    //    {
                    //        //ListView.Columns[i].SummaryItem.DisplayFormat = "{0:c}";
                    //        ListView.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                    //        ListView.Columns[i].DisplayFormat.FormatString = "f1";
                    //        ListView.Columns[i].AppearanceHeader.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                    //        ListView.Columns[i].AppearanceHeader.Options.UseTextOptions = true;
                    //    }

                    //}
                    break;
            }

        }

        //public static void subIniGrid(DevExpress.XtraGrid.Views.BandedGrid.AdvBandedGridView  ListView, enumGridStyle style)
        //{
        //    switch (style)
        //    {
        //        case enumGridStyle.ViewStyle:
        //            ListView.OptionsView.ColumnAutoWidth = false;
        //            ListView.OptionsView.EnableAppearanceEvenRow = true;
        //            ListView.OptionsView.ShowFooter = true;
        //            ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
        //            ListView.IndicatorWidth = 40;
        //            ListView.HorzScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
        //            ListView.VertScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
        //            ListView.Appearance.OddRow.BackColor = System.Drawing.Color.White;
        //            ListView.Appearance.OddRow.BackColor2 = System.Drawing.Color.White;

        //            ListView.Appearance.EvenRow.BackColor = System.Drawing.Color.WhiteSmoke;
        //            ListView.Appearance.EvenRow.BackColor2 = System.Drawing.Color.WhiteSmoke;

        //            ListView.Appearance.FocusedRow.BackColor = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.FocusedRow.BackColor2 = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.FocusedRow.ForeColor = Color.White;

        //            ListView.Appearance.SelectedRow.BackColor = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.SelectedRow.BackColor2 = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.SelectedRow.ForeColor = Color.White;

        //            ListView.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.HideSelectionRow.BackColor2 = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.White;

        //           
        //            break;
        //        case enumGridStyle.InputStyle:
        //            ListView.OptionsBehavior.Editable = true;

        //            // 默认当单击单元格或进入单元格时，选中单元格内容
        //            ListView.OptionsBehavior.AutoSelectAllInEditor = true;
        //            // 自动建立列
        //            ListView.OptionsBehavior.AutoPopulateColumns = true;

        //            //View Options选项
        //            //默认显示过滤面板，即当Header能定制过滤，是否显示过滤面板
        //            ListView.OptionsFilter.ShowAllTableValuesInFilterPopup = true;
        //            // 默认不显示分组面板
        //            ListView.OptionsView.ShowGroupPanel = false;
        //            // 默认显示指示器
        //            ListView.OptionsView.ShowIndicator = true;
        //            // 默认显示列的总宽度和视图的宽度不相等
        //            ListView.OptionsView.ColumnAutoWidth = false;
        //            // 默认显示视图脚
        //            ListView.OptionsView.ShowFooter = true;

        //            // Print Options选项
        //            // 不能自动宽度
        //            ListView.OptionsPrint.AutoWidth = false;

        //            // Cell Navigation Options选项
        //            // 按Enter进入下一列
        //            ListView.OptionsNavigation.EnterMoveNextColumn = true;

        //            for (int col = 0; col < ListView.Columns.Count; col++)
        //            {
        //                ListView.Columns[col].OptionsColumn.AllowEdit = true;
        //                ListView.Columns[col].OptionsColumn.AllowFocus = true;

        //            }

        //            // 焦点自动到新行
        //            ListView.OptionsNavigation.AutoFocusNewRow = true;
        //            ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;

        //            //ListView.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;

        //            ListView.Appearance.Row.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;

        //            ListView.Appearance.FocusedRow.BackColor = System.Drawing.Color.White;
        //            ListView.Appearance.FocusedRow.BackColor2 = System.Drawing.Color.White;
        //            ListView.Appearance.FocusedRow.ForeColor = Color.Black;

        //            ListView.Appearance.SelectedRow.BackColor = System.Drawing.Color.White;
        //            ListView.Appearance.SelectedRow.BackColor2 = System.Drawing.Color.White;
        //            ListView.Appearance.SelectedRow.ForeColor = Color.Black;

        //            ListView.Appearance.FocusedCell.BackColor = System.Drawing.Color.White;
        //            ListView.Appearance.FocusedCell.ForeColor = System.Drawing.Color.Black;

        //            break;
        //        default:
        //            //StyleFormatCondition styleCondition = new StyleFormatCondition();
        //            //ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None;
        //            //ListView.OptionsSelection.EnableAppearanceFocusedRow = false;
        //            //ListView.OptionsSelection.EnableAppearanceFocusedCell = false;
        //            //ListView
        //            //// Adds the style condition to the collection
        //            //ListView.FormatConditions.Add(styleCondition);
        //            //styleCondition.Value1 = 0;
        //            //styleCondition.Value2 = 0;
        //            //// Modifying the appearance settings
        //            //styleCondition.Appearance.BackColor = Color.White;
        //            //styleCondition.Appearance.Font = new Font(ListView.Appearance.Row.Font, FontStyle.Bold);
        //            //styleCondition.Appearance.ForeColor = Color.White;
        //            //styleCondition.Condition = FormatConditionEnum.Equal;
        //            //styleCondition.ApplyToRow = false;

        //            ListView.OptionsView.ColumnAutoWidth = false;
        //            ListView.OptionsView.EnableAppearanceEvenRow = true;
        //            ListView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
        //            ListView.IndicatorWidth = 40;
        //            ListView.HorzScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
        //            ListView.VertScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
        //            ListView.Appearance.OddRow.BackColor = System.Drawing.Color.White;
        //            ListView.Appearance.OddRow.BackColor2 = System.Drawing.Color.White;

        //            ListView.Appearance.EvenRow.BackColor = System.Drawing.Color.WhiteSmoke;
        //            ListView.Appearance.EvenRow.BackColor2 = System.Drawing.Color.WhiteSmoke;

        //            ListView.Appearance.FocusedRow.BackColor = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.FocusedRow.BackColor2 = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.FocusedRow.ForeColor = Color.White;

        //            ListView.Appearance.SelectedRow.BackColor = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.SelectedRow.BackColor2 = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.SelectedRow.ForeColor = Color.White;

        //            ListView.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.HideSelectionRow.BackColor2 = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.White;

        //            ListView.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.HideSelectionRow.BackColor2 = System.Drawing.Color.RoyalBlue;
        //            ListView.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.White;

        //            ListView.Appearance.HeaderPanel.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
        //            ListView.Appearance.HeaderPanel.Options.UseTextOptions = true;
        //            ListView.OptionsView.RowAutoHeight = false;
        //            ListView.ColumnPanelRowHeight = 30;
        //            //设定小数位数
        //            for (int i = 0; i < ListView.Columns.Count; i++)
        //            {
        //                if (ListView.Columns[i].ColumnType.ToString() == "System.Decimal")
        //                {
        //                    //ListView.Columns[i].SummaryItem.DisplayFormat = "{0:c}";
        //                    ListView.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
        //                    ListView.Columns[i].DisplayFormat.FormatString = "f1";
        //                    ListView.Columns[i].AppearanceHeader.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
        //                    ListView.Columns[i].AppearanceHeader.Options.UseTextOptions = true;
        //                }

        //            }
        //            break;
        //    }

        //}

        /// <summary>
        /// 读取系统的Dat配置文件
        /// </summary>
        public static void subGetIniData()
        {
            try
            {
                sysrun sysSetup = (sysrun)serial.DeserializeBinary(Application.StartupPath + @"\NNLInterface.dat");
                common.sysParameter = sysSetup;
                RWLang = new rwconfig(common.GetSolutionPath(Application.StartupPath) + @"Language\Chinese.ini");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, common.sysParameter.MessageInf, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        /// <summary>
        /// 取得当前程序的当前路径
        /// </summary>
        /// <param name="_Path">路径字符串</param>
        /// <returns>当前路径</returns>
        public static string GetSolutionPath(string _Path)
        {
            return (_Path.Substring(_Path.Length - 1, 1) != @"\") ? _Path + @"\" : _Path;
        }

        /// <summary>
        /// 取得Ini文件所对应的项目的值
        /// </summary>
        /// <param name="_Section">区域</param>
        /// <param name="_Key">项目</param>
        /// <returns>返回项目所对应的值</returns>
        public static string GetLanguageWord(string _Section, string _Key)
        {
            return RWLang.ReadTextFile(_Section, _Key);
        }


        public static void SetFormLanguage(Control _ctl, Form _frm, string _frmname)
        {
            switch (_ctl.GetType().ToString().Trim())
            {
                //case "DevExpress.XtraEditors.ButtonEdit":
                //    ((DevExpress.XtraEditors.ButtonEdit)_ctl).Properties.Buttons[0].Caption = GetLanguageWord(_frmname, _ctl.Name );
                //    ((DevExpress.XtraEditors.ButtonEdit)_ctl).Font = common.sysParameter.ButtonEditFont;
                //    ((DevExpress.XtraEditors.ButtonEdit)_ctl).Properties.Buttons[0].Appearance.Font = common.sysParameter.ButtonEditFont;
                //    break;
                case "DevExpress.XtraGrid.GridControl":
                    DevExpress.XtraGrid.Views.Grid.GridView ListView = ((DevExpress.XtraGrid.Views.Grid.GridView)((DevExpress.XtraGrid.GridControl)_ctl).DefaultView);
                    if (ListView.Columns.Count > 0)
                    {
                        for (int col = 0; col < ListView.Columns.Count; col++)
                        {
                            ListView.Columns[col].Caption = common.GetLanguageWord(_frmname, ListView.Columns[col].Name.Trim());
                        }
                    }
                    break;
                //case "DevExpress.XtraBars.BarDockControl":
                //    if (((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items.Count > 0)
                //    {
                //        for (int index = 0; index < ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items.Count; index++)
                //        {
                //            if (((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items[index].Tag != null)
                //            {
                //                ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items[index].Caption = GetLanguageWord(_frmname, ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items[index].Name.ToString());
                //            }
                //        }

                //        for (int col = 0; col < ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.RepositoryItems.Count; col++)
                //        {
                //            if (((DevExpress.XtraBars.BarDockControl)_ctl).Manager.RepositoryItems[col].GetType().ToString() == "DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit")
                //            {
                //                DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit reItem = ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.RepositoryItems[col] as DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit;
                //                reItem.DisplayMember = reItem.DisplayMember.ToUpper();
                //                reItem.ValueMember = reItem.ValueMember.ToUpper();
                //                if (reItem.Columns.Count >= 1)
                //                    reItem.Columns[0].FieldName = reItem.Columns[0].FieldName.ToUpper();
                //            }
                //        }
                //        ((DevExpress.XtraBars.BarDockControl)_ctl).Appearance.Font = common.sysParameter.ButtonEditFont;
                //        ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Bars[0].Appearance.Font = common.sysParameter.ButtonEditFont;  //可通过此属性取得bar的集合，很有用
                //    }
                //    break;
                //case "DevExpress.XtraEditors.LabelControl":
                //    _ctl.Text = GetLanguageWord(_frmname, _ctl.Name);
                //    _ctl.Font = common.sysParameter.ButtonEditFont;
                //    break;
                //case "DevExpress.XtraEditors.GroupControl":
                //    _ctl.Text = GetLanguageWord(_frmname, _ctl.Tag == null ? "" : _ctl.Tag.ToString()).Trim();
                //    _ctl.Font = common.sysParameter.ButtonEditFont;

                //    if (_ctl.HasChildren)
                //        foreach (Control childControl in _ctl.Controls)
                //        {
                //            SetFormLanguage(childControl, _frm, _frmname);
                //        }
                //    break;

                //case "DevExpress.XtraEditors.CheckEdit":
                //    string strCaption = GetLanguageWord(_frmname, _ctl.Name == null ? "" : _ctl.Name.ToString()).Trim();
                //    _ctl.Text = strCaption;
                //    _ctl.Font = common.sysParameter.ButtonEditFont;
                //    break;
                //case "DevExpress.XtraEditors.MemoEdit":
                //    if (_childctl.Tag.ToString() != "N")
                //        _childctl.Text = GetLanguageWord(_frmname, _childctl.Tag == null ? "" : _childctl.Name.ToString()).Trim();
                //    _childctl.Font = common.sysParameter.ButtonEdit;
                //    break;
                //case "DevExpress.XtraEditors.LookUpEdit":
                //    //((DevExpress.XtraEditors.LookUpEdit)_ctl).Properties.PopupWidth = 350;
                //    //((DevExpress.XtraEditors.LookUpEdit)_ctl).Properties.DropDownRows = 12;
                    
                //    ((DevExpress.XtraEditors.LookUpEdit)_ctl).Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _ctl.Name);
                //    for (int i = 0; i < ((DevExpress.XtraEditors.LookUpEdit)_ctl).Properties.Columns.Count ; i++)
                //    {
                //        ((DevExpress.XtraEditors.LookUpEdit)_ctl).Properties.Columns[i].Caption  = GetLanguageWord(_frmname, _ctl.Name + ((DevExpress.XtraEditors.LookUpEdit)_ctl).Properties.Columns[i].FieldName);
                //    }
                //    _ctl.Font = common.sysParameter.ButtonEditFont;
                //    break;
                //case "DevExpress.XtraEditors.DateEdit":
                //    ((DevExpress.XtraEditors.DateEdit)_ctl).Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _ctl.Name);
                //    _ctl.Font = common.sysParameter.ButtonEditFont;
                //    break;

                //case "DevExpress.XtraEditors.CalcEdit":
                //    ((DevExpress.XtraEditors.CalcEdit)_ctl).Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _ctl.Name);
                //    _ctl.Font = common.sysParameter.ButtonEditFont;
                //    break;
                //case "DevExpress.XtraEditors.LookUpEdit":
                //    DevExpress.XtraEditors.LookUpEdit edit = ((DevExpress.XtraEditors.LookUpEdit)_childctl);

                //    edit.Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _childctl.Name);
                //    //给lookupedit的各列的caption敷值
                //    for (int i = 0; i < edit.Properties.Columns.Count; i++)
                //    {
                //        edit.Properties.Columns[i].Caption = GetLanguageWord(_frmname, "Col_" + edit.Properties.Columns[i].FieldName);
                //    }
                //    _childctl.Font = common.sysParameter.ButtonEdit;
                //    break;

                //case "DevExpress.XtraEditors.SimpleButton":
                //    _ctl.Text = GetLanguageWord(_frmname, _ctl.Name );
                //    _ctl.Font = common.sysParameter.ButtonEditFont;
                //    break;
                //case "System.Windows.Forms.ToolStrip":
                //    ((System.Windows.Forms.ToolStrip)_ctl).Font = common.sysParameter.ButtonEditFont;
                //    for (int col = 0; col < ((System.Windows.Forms.ToolStrip)(_ctl)).Items.Count; col++)
                //    {
                //        ((System.Windows.Forms.ToolStrip)(_ctl)).Items[col].Text = GetLanguageWord(_frmname, ((System.Windows.Forms.ToolStrip)(_ctl)).Items[col].Name);
                //        if (((System.Windows.Forms.ToolStrip)(_ctl)).Items[col].GetType().ToString() == "System.Windows.Forms.ToolStripDropDownButton")
                //        {
                //            System.Windows.Forms.ToolStripDropDownButton dropButton = (System.Windows.Forms.ToolStripDropDownButton)((System.Windows.Forms.ToolStrip)(_ctl)).Items[col];
                //            if (dropButton.DropDownItems.Count > 0)
                //            {
                //                for (int row = 0; row < dropButton.DropDownItems.Count; row++)
                //                {
                //                    dropButton.DropDownItems[row].Text = GetLanguageWord(_frmname, dropButton.DropDownItems[row].Name.ToString().Trim());
                //                    dropButton.DropDownItems[row].Font = common.sysParameter.ButtonEditFont;
                //                }
                //            }

                //        }
                //    }
                //    break;
                //case "DividerPanel.DividerPanel":
                //    DividerPanel.DividerPanel divPanel = (DividerPanel.DividerPanel)_ctl;
                //    divPanel.Title = GetLanguageWord(_frmname, _ctl.Tag == null ? "" : _ctl.Tag.ToString());
                //    _ctl.Font = common.sysParameter.ButtonEdit;
                //    break;
               
                case "DevExpress.XtraLayout.LayoutControl":
                    if (_ctl.HasChildren)
                        foreach (Control childControl in _ctl.Controls)
                        {
                            SetFormLanguage(childControl, _frm, _frmname);
                        }

                    break;

                //case "DevExpress.XtraEditors.XtraScrollableControl":
                //    if (_ctl.HasChildren)
                //        foreach (Control childControl in _ctl.Controls)
                //        {
                //            SetFormLanguage(childControl, _frm, _frmname);
                //        }

                //    break;

            }
        }

        public static void GetResourceString(Form _frm, DevExpress.XtraGrid.Views.Grid.GridView ListView)
        {
            if (ListView.Columns.Count > 0)
            {
                for (int col = 0; col < ListView.Columns.Count; col++)
                {
                    ListView.Columns[col].Caption = common.GetLanguageWord(_frm.Name, ListView.Columns[col].Name);
                }
            }
        }

        public static void GetResourceString(string frmName, DevExpress.XtraGrid.Views.Grid.GridView ListView)
        {
            if (ListView.Columns.Count > 0)
            {
                for (int col = 0; col < ListView.Columns.Count; col++)
                {
                    ListView.Columns[col].Caption = common.GetLanguageWord(frmName, ListView.Columns[col].Name);
                }
            }
        }

        public static void GetResourceString(string frmName, System.Windows.Forms.Form frmStance, DevExpress.XtraGrid.Views.Grid.GridView ListView)
        {
            frmStance.Text = GetLanguageWord(frmStance.Name, "Name");
            if (ListView.Columns.Count > 0)
            {
                for (int col = 0; col < ListView.Columns.Count; col++)
                {
                    ListView.Columns[col].Caption = common.GetLanguageWord(frmName, ListView.Columns[col].Name);
                }
            }
        }

        public static void GetResourceString(Form _frm)
        {
            string _frmname = _frm.Name.ToUpper().Trim();
            string strCaption = "";
            //对窗体的标题栏处理
            _frm.Text = GetLanguageWord(_frmname, "Name");
            //对窗体的控件处理
            foreach (Control _ctl in _frm.Controls)
            {
                switch (_ctl.GetType().ToString().Trim())
                {
                    case "DevExpress.XtraEditors.ButtonEdit":
                        ((DevExpress.XtraEditors.ButtonEdit)_ctl).Properties.Buttons[0].Caption = GetLanguageWord(_frmname, _ctl.Tag == null ? "" : _ctl.Tag.ToString());
                        break;
                    case "DevExpress.XtraGrid.GridControl":
                        DevExpress.XtraGrid.Views.Grid.GridView ListView = ((DevExpress.XtraGrid.Views.Grid.GridView)((DevExpress.XtraGrid.GridControl)_ctl).DefaultView);
                        if (ListView.Columns.Count > 0)
                        {
                            for (int col = 0; col < ListView.Columns.Count; col++)
                            {
                                ListView.Columns[col].Caption = common.GetLanguageWord(_frmname, ListView.Columns[col].Name);
                            }
                        }
                        break;
                    case "DevExpress.XtraBars.BarDockControl":
                        if (((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items.Count > 0)
                        {
                            for (int index = 0; index < ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items.Count; index++)
                            {
                                if (((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items[index].Tag != null)
                                {
                                    ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items[index].Caption = GetLanguageWord(_frmname, ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.Items[index].Name.ToString());
                                }
                            }

                            for (int col = 0; col < ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.RepositoryItems.Count; col++)
                            {
                                if (((DevExpress.XtraBars.BarDockControl)_ctl).Manager.RepositoryItems[col].GetType().ToString() == "DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit")
                                {
                                    DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit reItem = ((DevExpress.XtraBars.BarDockControl)_ctl).Manager.RepositoryItems[col] as DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit;
                                    //如果用于oracle，要加上以下语句
                                    //reItem.DisplayMember = reItem.DisplayMember.ToLower();
                                    //reItem.ValueMember = reItem.ValueMember.ToLower();
                                    reItem.PopupWidth = 350;
                                    reItem.DropDownRows = 12;
                                    reItem.EditValueChangedFiringMode = DevExpress.XtraEditors.Controls.EditValueChangedFiringMode.Buffered;
                                    if (reItem.Columns.Count >= 1)
                                    {
                                        for (int i = 0; i < reItem.Columns.Count; i++)
                                        {
                                            reItem.Columns[i].Caption = GetLanguageWord(_frmname, reItem.Columns[i].Caption);
                                        }
                                    }
                                    //reItem.Columns[0].FieldName = reItem.Columns[0].FieldName.ToLower();

                                }
                            }
                        }
                        break;
                    case "DevExpress.XtraEditors.LabelControl":
                        _ctl.Text = GetLanguageWord(_frmname, _ctl.Name);
                        break;
                    case "DevExpress.XtraEditors.GroupControl":
                        _ctl.Text = GetLanguageWord(_frmname, _ctl.Tag == null ? "" : _ctl.Tag.ToString()).Trim();
                        foreach (System.Windows.Forms.Control _childctl in _ctl.Controls)
                        {
                            switch (_childctl.GetType().ToString().Trim())
                            {
                                case "DevExpress.XtraEditors.ButtonEdit":
                                    strCaption = GetLanguageWord(_frmname, _childctl.Tag == null ? "" : _childctl.Name.ToString()).Trim();
                                    if (strCaption != "") ((DevExpress.XtraEditors.ButtonEdit)_childctl).Properties.Buttons[0].Caption = strCaption;
                                    break;
                                case "DevExpress.XtraEditors.LabelControl":
                                    strCaption = GetLanguageWord(_frmname, _childctl.Tag == null ? "" : _childctl.Name.ToString()).Trim();
                                    if (strCaption != "") ((DevExpress.XtraEditors.LabelControl)_childctl).Text = strCaption;
                                    break;
                                case "DevExpress.XtraEditors.CheckEdit":
                                    strCaption = GetLanguageWord(_frmname, _childctl.Name == null ? "" : _childctl.Name.ToString()).Trim();
                                    _childctl.Text = strCaption;
                                    break;
                                //case "DevExpress.XtraEditors.MemoEdit":
                                //    if (_childctl.Tag.ToString() != "N")
                                //        _childctl.Text = GetLanguageWord(_frmname, _childctl.Tag == null ? "" : _childctl.Name.ToString()).Trim();
                                //    _childctl.Font = common.sysParameter.ButtonEdit;
                                //    break;
                                case "DevExpress.XtraEditors.LookUpEdit":
                                    DevExpress.XtraEditors.LookUpEdit edit = ((DevExpress.XtraEditors.LookUpEdit)_childctl);
                                    edit.Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _childctl.Name);
                                    //给lookupedit的各列的caption敷值
                                    for (int i = 0; i < edit.Properties.Columns.Count; i++)
                                    {
                                        edit.Properties.Columns[i].Caption = GetLanguageWord(_frmname, "Col_" + edit.Properties.Columns[i].FieldName);
                                    }
                                    break;
                                case "DevExpress.XtraEditors.DateEdit":
                                    ((DevExpress.XtraEditors.DateEdit)_childctl).Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _childctl.Name);
                                    break;

                                case "DevExpress.XtraEditors.CalcEdit":
                                    ((DevExpress.XtraEditors.CalcEdit)_childctl).Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _childctl.Name);
                                    break;
                                //case "DevExpress.XtraEditors.LookUpEdit":
                                //    DevExpress.XtraEditors.LookUpEdit exedit = ((DevExpress.XtraEditors.LookUpEdit)_childctl);
                                //    exedit.Properties.Buttons[1].Caption = GetLanguageWord(_frmname, _childctl.Name);
                                //    exedit.Properties.DropDownRows = 12;
                                //    //给lookupedit的各列的caption敷值
                                //    for (int i = 0; i < exedit.Properties.Columns.Count; i++)
                                //    {
                                //        exedit.Properties.Columns[i].Caption = GetLanguageWord(_frmname, "Col_" + exedit.Properties.Columns[i].FieldName);
                                //    }
                                //    _childctl.Font = common.sysParameter.ButtonEdit;
                                //    break;

                            }
                        }
                        break;
                    case "DevExpress.XtraEditors.SimpleButton":
                        _ctl.Text = GetLanguageWord(_frmname, _ctl.Tag == null ? "" : _ctl.Tag.ToString());
                        break;
                    case "System.Windows.Forms.ToolStrip":

                        for (int col = 0; col < ((System.Windows.Forms.ToolStrip)(_ctl)).Items.Count; col++)
                        {
                            ((System.Windows.Forms.ToolStrip)(_ctl)).Items[col].Text = GetLanguageWord(_frmname, ((System.Windows.Forms.ToolStrip)(_ctl)).Items[col].Name);
                            if (((System.Windows.Forms.ToolStrip)(_ctl)).Items[col].GetType().ToString() == "System.Windows.Forms.ToolStripDropDownButton")
                            {
                                System.Windows.Forms.ToolStripDropDownButton dropButton = (System.Windows.Forms.ToolStripDropDownButton)((System.Windows.Forms.ToolStrip)(_ctl)).Items[col];
                                if (dropButton.DropDownItems.Count > 0)
                                {
                                    for (int row = 0; row < dropButton.DropDownItems.Count; row++)
                                    {
                                        dropButton.DropDownItems[row].Text = GetLanguageWord(_frmname, dropButton.DropDownItems[row].Name.ToString().Trim());
                                    }
                                }

                            }
                        }
                        break;
                    //case "DividerPanel.DividerPanel":
                    //    DividerPanel.DividerPanel divPanel = (DividerPanel.DividerPanel)_ctl;
                    //    divPanel.Title = GetLanguageWord(_frmname, _ctl.Tag == null ? "" : _ctl.Tag.ToString());
                    //    //_ctl.Font = common.sysParameter.ButtonEdit;
                    //    break;

                }
            }

        }
        /// <summary>
        /// 本地化窗体
        /// </summary>
        /// <param name="_frm">要改变Form的实例</param>
        /// <param name="_frmname">要读取的INI表节名</param>
        public static void GetResourceString(Form _frm, string _frmname)
        {
            if (GetLanguageWord(_frmname,"frmname")!="frmname")
               //对窗体的标题栏处理
                _frm.Text = GetLanguageWord(_frmname, "frmname");
            //对窗体的控件处理
            foreach (Control _ctl in _frm.Controls)
            {
                SetFormLanguage(_ctl, _frm, _frmname);
            }

        }


        //初始化接口
        /// <summary>
        /// 窗体皮肤设定
        /// </summary>
        public static void iniSkin()
        {
            //皮肤设定
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.Skins.SkinManager.EnableMdiFormSkins();

            DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.Skins.FormSkins).Assembly);
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.Skins.SkinManager.EnableFormSkins();
            Application.EnableVisualStyles();


            //本地化控件
            //DevExpress.XtraBars.Localization.BarLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraBarsLocalizationCHS();
            //DevExpress.XtraLayout.Localization.LayoutLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraLayoutLocalizationCHS();
            //DevExpress.XtraEditors.Controls.Localizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraEditorsLocalizationCHS();
            //DevExpress.XtraGrid.Localization.GridLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraGridLocalizationCHS();
            //DevExpress.XtraNavBar.NavBarLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraNavBarLocalizationCHS();
            //DevExpress.XtraPrinting.Localization.PreviewLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraPrintingLocalizationCHS();
            LocationControl();
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(DevExpress.Skins.SkinManager.Default.Skins[common.sysParameter.formskin == null ? 21 : Convert.ToInt32(common.sysParameter.formskin)].SkinName);
        }


        /// <summary>
        /// 本地化控件
        /// </summary>
        public static void LocationControl()
        {
            new ChineseLanguage.Chinese();

        }
        /// <summary>
        /// 初始化连接字符串
        /// </summary>
        public static string  GetConnectString()
        {
            return "SERVER=" + common.sysParameter.ServerName.Trim() + ";"
                            + "UID=" + common.sysParameter.UserName.Trim() + ";"
                            + "PWD=" + common.sysParameter.PassWord.Trim() + ";"
                            + "DATABASE=" + common.sysParameter.DataBaseName.Trim();
        }

        /// <summary>
        /// 初始化连接字符串
        /// </summary>
        public static string GetERPConnectString()
        {
            return "SERVER=" + common.sysParameter.ErpServer.Trim() + ";"
                            + "UID=" + common.sysParameter.ErpUser.Trim() + ";"
                            + "PWD=" + common.sysParameter.ErpPassWord.Trim() + ";"
                            + "DATABASE=" + common.sysParameter.ErpDataBase.Trim();
        }

        public static void subSelectData(DevExpress.XtraGrid.GridControl ListGrid, DevExpress.XtraGrid.Views.Grid.GridView ListView)
        {
            DataTable viewt = (DataTable)ListGrid.DataSource;
            DataRow[] dr;

            if (ListView.ActiveFilterEnabled)
                dr = viewt.Select(ListView.RowFilter);
            else
                dr = viewt.Select("");

            for (int i = 0; i < dr.Length; i++)
            {
                dr[i][0] = Convert.ToInt32(ListGrid.Tag) == 1 ? 0 : 1;
            }

            viewt = null;
            dr = null;

            ListGrid.Tag = Convert.ToInt32(ListGrid.Tag) == 1 ? 0 : 1;
        }
    }
}
